﻿using System;
using System.Reactive.Concurrency;
using System.Windows.Forms;

namespace ReactiveXLearning
{
    public partial class frmBase : Form
    {
        protected ControlScheduler control_scheduler;

        public frmBase()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 运行指定委托在主窗体线程
        /// </summary>
        /// <param name="action">要运行的委托</param>
        protected void RunOnUI(Action action)
        {
            if (IsDisposed) return;
            control_scheduler = control_scheduler ?? new ControlScheduler(this);
            control_scheduler.Schedule(action);
        }

        /// <summary>
        /// 显示消息提示框
        /// </summary>
        /// <param name="msg">提示消息</param>
        protected void ShowMessage(string msg)
        {
            RunOnUI(() => MessageBox.Show(msg));
        }
    }
}
